﻿@{
    ViewBag.Title = "TrafficDetail";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
@model TrafficModel
<div class="panel">
    <div class="panel-header clearfix">
        <h3 class="pull-left">统计日期：@Model.Date.ToString("yyyy-MM-dd")</h3>
    </div>
    <div class="panel-body" id="grid">
    </div>
</div>

<script type="text/javascript">
    var Grid = BUI.Grid,
    Store = BUI.Data.Store,
    columns = [
      { title: '来源', sortable: false, dataIndex: 'SE' },
      { title: '访问页面', sortable: false, dataIndex: 'CurrentUrl' },
      { title: 'IP', sortable: false, dataIndex: 'IP' },
      { title: '访问时间', sortable: false, dataIndex: 'CreateTime' },
      {
          title: '操作', sortable: false, dataIndex: 'ID',
          renderer: function (value, obj) {
              return '<span class="grid-command" onclick="DeletePage(\'' + value + '\')" >删除</span>';
          }
      }
    ];
    //加载列表
    var store = new Store({
        url: '/Admin/System/AjaxGetTrafficInfo?Date=@Model.Date',
        proxy: {
            limitParam: 'pageSize',
            method: 'post'
        },
        autoLoad: true,
        pageSize: 10
    }),
    grid = new Grid.Grid({
        render: '#grid',
        loadMask: true,
        forceFit: true,
        plugins: [Grid.Plugins.AutoFit, Grid.Plugins.CheckSelection],
        columns: columns,
        store: store,
        bbar: {
            items: [{
                id: 'delAllBtn',
                elStyle: { 'margin-top': '3px' },
                btnCls: 'button button-small',
                text: '批量删除'
            }],
            pagingBar: true
        }
    });
      grid.render();
      function DeletePage(id) {
          if (confirm('确定删除？')) {
              $.ajax({
                  type: 'post',
                  data: { ids: id },
                  url: '/Admin/System/DeleteTraffic',
                  success: function () {
                      var obj = {};
                      obj.pageIndex = 0;
                      obj.start = 0;
                      store.load(obj);
                  }
              })
          }
      }
      $('#delAllBtn').click(function () {
          var selected = grid.getSelection();
          if (selected.length == 0)
              return false;
          var dateArray = [];
          for (var i = 0; i < selected.length; i++) {
              dateArray.push(selected[i].ID);
          }
          DeletePage(dateArray);
      })
</script>
